package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SubsidyInfoAddDTO;
import org.jsola.hr.dto.SubsidyInfoUpdateDTO;
import org.jsola.hr.entity.SubsidyInfoDO;
import org.jsola.hr.query.SubsidyInfoQuery;
import org.jsola.hr.service.ISubsidyInfoService;
import org.jsola.hr.vo.SubsidyInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class SubsidyInfoTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISubsidyInfoService subsidyInfoService;

    /**
     * 生成add测试数据
     * @return SubsidyInfoAddDTO
     */
    public SubsidyInfoAddDTO getSubsidyInfoAddDTO(){
        SubsidyInfoAddDTO subsidyInfoAddDTO = new SubsidyInfoAddDTO();
        subsidyInfoAddDTO.setProgId(getRandomValue("varchar",32));
        subsidyInfoAddDTO.setName(getRandomValue("varchar",255));
        subsidyInfoAddDTO.setType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        subsidyInfoAddDTO.setSendDate(SafeKit.getInteger(getRandomValue("int",11)));
        subsidyInfoAddDTO.setAmount(SafeKit.getInteger(getRandomValue("int",11)));
        subsidyInfoAddDTO.setCompanyId(getRandomValue("varchar",32));
        return subsidyInfoAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SubsidyInfoUpdateDTO
     */
    public SubsidyInfoUpdateDTO getSubsidyInfoUpdateDTO(SubsidyInfoVO subsidyInfoVO){
        return subsidyInfoService.selectDOById(subsidyInfoVO.getId(), SITE_ID).to(SubsidyInfoUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SubsidyInfoQuery
     */
    public SubsidyInfoQuery getSubsidyInfoQuery() {
        SubsidyInfoQuery subsidyInfoQuery = new SubsidyInfoQuery();
        List<SubsidyInfoDO> subsidyInfoDOList = subsidyInfoService.list(new SubsidyInfoDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(subsidyInfoDOList)) {
            SubsidyInfoDO subsidyInfoDO = subsidyInfoDOList.get(0);
            subsidyInfoQuery = subsidyInfoDO.to(SubsidyInfoQuery.class);
            if (subsidyInfoDO.getGmtCreate() != null) {
                subsidyInfoQuery.setGmtCreateStart(DateKit.getBeforeDay(subsidyInfoDO.getGmtCreate(),-1));
                subsidyInfoQuery.setGmtCreateEnd(DateKit.getBeforeDay(subsidyInfoDO.getGmtCreate(),1));
            }
            if (subsidyInfoDO.getGmtModified() != null) {
                subsidyInfoQuery.setGmtModifiedStart(DateKit.getBeforeDay(subsidyInfoDO.getGmtModified(),-1));
                subsidyInfoQuery.setGmtModifiedEnd(DateKit.getBeforeDay(subsidyInfoDO.getGmtModified(),1));
            }
        }
        return subsidyInfoQuery;
    }

    /**
     * 保存示例
     * @return SubsidyInfoVO
     */
    public SubsidyInfoVO saveSubsidyInfoExample(){
        SubsidyInfoAddDTO addDTO = this.getSubsidyInfoAddDTO();
        SubsidyInfoVO subsidyInfoVO = subsidyInfoService.save(addDTO,buildTokenUser());
        return subsidyInfoVO;
    }


}

